#!/bin/bash

ES_ID=`ps -ef |grep elasticsearch |grep -w 'elasticsearch'|grep -v 'grep'|awk '{print $2}'`

if [ $ES_ID ];then # 这里判断 ES 进程是否存在
echo "[info]当前 ES 进程 ID 为:$ES_ID"
else
echo "[error] ES 进程不存在! ES 开始自动重启..."
su - elastic -c "/usr/local/elastic/elasticsearch-6.1.1/bin/elasticsearch -d"
fi